package com.kilon.workfaq.service.write.impl;

import com.kilon.workfaq.entity.PostPo;
import com.kilon.workfaq.mapper.write.PostWriteMapper;
import com.kilon.workfaq.service.write.PostWriteService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

/**
 * 博客文章表(Post)表服务实现类
 *
 * @author makejava
 * @since 2023-02-23 02:18:57
 */
@Service("postWriteService")
public class PostWriteServiceImpl implements PostWriteService {
    @Resource
    private PostWriteMapper postWriteMapper;

    /**
     * 新增数据
     *
     * @param post 实例对象
     * @return 实例对象
     */
    @Override
    public PostPo insert(PostPo post) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String currentTime = format.format(Calendar.getInstance().getTime());
        post.setCreatetime(currentTime);
        post.setAae100("1");
        this.postWriteMapper.insert(post);
        return post;
    }

    /**
     * 修改数据
     *
     * @param post 实例对象
     * @return 实例对象
     */
    @Override
    public boolean update(PostPo post) {
        return this.postWriteMapper.update(post) == 1;
    }

    /**
     * 通过主键删除数据
     *
     * @return 是否成功
     */
    @Override
    public boolean deleteById(PostPo post) {
        return this.postWriteMapper.deleteById(post.getId()) == 1;
    }
}
